package com.joe.xl.common.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.Properties;

public class ReadConfig {
	private final static Logger logger = LoggerFactory.getLogger(ReadConfig.class);

    //加载配置文件 方法。
    public static Properties load(String url) {
        Properties prop = new Properties();
        try {
            InputStream in = ReadConfig.class.getResourceAsStream(url);
            // /加载属性列表
            prop.load(in);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            logger.error(e.getMessage());
        }

        return prop;
    }

    public static Properties loadPropertiesFromFile(String filename) {
        InputStream inputStream = null;
        Throwable   var2        = null;

        Properties var4 = new Properties();
        try {
            File file = Paths.get("conf", filename).toFile();
            inputStream = new FileInputStream(file);
            var4.load(inputStream);
        } catch (Exception var13) {
            var2 = var13;
        } finally {
            if (inputStream != null) {
                if (var2 != null) {
                    try {
                        inputStream.close();
                    } catch (Throwable var12) {
                        logger.error(var12.getMessage());
                    }
                } else {
                    try {
                        inputStream.close();
                    } catch (Exception e) {
                        logger.error(e.getMessage());
                    }
                }
            }
        }

        return var4;
    }


    public static void main(String[] args) {
        Properties prop = ReadConfig.load("/config.properties");
        System.out.println(Boolean.parseBoolean(prop.getProperty("test")));
    }
}
